home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase Pro v7.0 / DATA1.CAB / Sample_Custom / DataButtons.cc next >
Encoding:
C/C++ Source or Header  |  1997-11-20  |  18.9 KB  |  664 lines

  1. //------------------------------------------------------------------------
  2. //
  3. //  DataButtons.CC  
  4. //
  5. //  Custom control library for data navigation and editing.
  6. //
  7. //  Control         Function 
  8. //  ----------      -----------------------------------------------
  9. //  BarDataVCR      Container consisting of BitmapFirst,
  10. //                  BitmapPrevious, BitmapNext and BitmapLast.
  11. //
  12. //  BarDataEdit     Container consisting of BitmapAppend,
  13. //                  BitmapDelete, BitmapSave, BitmapAbandon, 
  14. //                  BitmapFilter and BitmapLocate.
  15. //
  16. //  BitmapAppend    Add a new row.
  17. //               
  18. //  BitmapDelete    Remove current row without confirmation.
  19. //
  20. //  BitmapSave      Save changes to current row.
  21. //
  22. //  BitmapAbandon   Abandon changes to current row.
  23. //
  24. //  BitmapFilter    Switch to or run filter by form. 
  25. //
  26. //  BitmapLocate    Switch to or run query by form.
  27. //
  28. //  BitmapEdit      Switch to edit state from browse state.
  29. //                  This has no effect when rowset.autoEdit 
  30. //                  is true.
  31. //
  32. //  BitmapFirst     Move to first row.
  33. //
  34. //  BitmapPrevious  Move to previous row.
  35. //
  36. //  BitmapNext      Move to next row.
  37. //
  38. //  BitmapLast      Move to last row.
  39. //
  40. //  RowState        Displays current rowset state as: Closed,
  41. //                  Read Only, Update, Append, Filter or Locate.
  42. //
  43. //  All controls operate on the current form rowset. 
  44. //
  45. //  All DataButton controls except the current control are hidden 
  46. //  when switching to a filter or locate state. All DataButtons are 
  47. //  shown when switching out of a filter or locate state.
  48. //
  49. //  Button Control    Same Function As
  50. //  --------------    ----------------
  51. //  ButtonAppend      BitmapAppend
  52. //  ButtonDelete      BitmapDelete
  53. //  ButtonSave        BitmapSave
  54. //  ButtonAbandon     BitmapAbandon
  55. //  ButtonFilter      BitmapFilter
  56. //  ButtonLocate      BitmapLocate
  57. //  ButtonEdit        BitmapEdit
  58. //  ButtonFirst       BitmapFirst
  59. //  ButtonPrevious    BitmapPrevious
  60. //  ButtonNext        BitmapNext
  61. //  ButtonLast        BitmapLast
  62. //
  63. //  Visual dBASE Samples Group
  64. //  $Revision:   1.6  $
  65. //
  66. //  Copyright (c) 1997, Borland International, Inc. All rights reserved. 
  67. //
  68. //------------------------------------------------------------------------
  69.  
  70. #define DATACONTROLS1 "BITMAPAPPEND,BITMAPDELETE,BITMAPSAVE,BITMAPABANDON,BITMAPLOCATE,BITMAPFILTER,BITMAPEDIT"
  71. #define DATACONTROLS2 ",BUTTONAPPEND,BUTTONDELETE,BUTTONSAVE,BUTTONABANDON,BUTTONLOCATE,BUTTONFILTER,BUTTONEDIT"
  72. #define DATACONTROLS3 ",BITMAPFIRST,BITMAPPREVIOUS,BITMAPNEXT,BITMAPLAST"
  73. #define DATACONTROLS4 ",BUTTONFIRST,BUTTONPREVIOUS,BUTTONNEXT,BUTTONLAST"
  74. #define DATACONTROLS5 ",BARDATAEDIT,BARDATAVCR"
  75.  
  76. // Bitmap Buttons
  77.  
  78. class BitmapData(ParentObj) of PushButton(ParentObj) custom 
  79.    SET TALK OFF
  80.    with ( this )
  81.       onOpen   := class::dataButton_onOpen
  82.       speedBar := true
  83.       text     := null
  84.       width    := 32
  85.       height   := 32
  86.       metric   := 6 // pixels
  87.       fontSize := 8
  88.    endwith
  89.  
  90.    function dataButton_onOpen
  91.       private rType
  92.       rType = this.form.rowset
  93.       this.visible = ( TYPE( "rType" ) <> "U" )
  94.    return ( this.visible )
  95.  
  96.    function toggleSearch( current )  
  97.       local bSearch, sControlList
  98.       local vProp
  99.  
  100.       bSearch = ( this.form.rowset.state == 4 ) OR ;
  101.                 ( this.form.rowset.state == 5 )
  102.       sControlList = UPPER( DATACONTROLS1 + DATACONTROLS2 + ;
  103.                             DATACONTROLS3 + DATACONTROLS4 )
  104.       sBarList     = UPPER( DATACONTROLS5 )
  105.                     
  106.       for i = 1 to this.form.elements.size
  107.  
  108.           if ( UPPER( this.form.elements[i].className ) $ sControlList )
  109.              if ( this.form.elements[i] <> current ) 
  110.                 this.form.elements[i].enabled = ( NOT bSearch ) 
  111.              endif      
  112.           endif
  113.  
  114.           if ( UPPER( this.form.elements[i].className ) $ sBarList )
  115.              this.form.elements[i].barToggle( bSearch, current )
  116.           endif
  117.       next
  118.       class::refreshRowState()
  119.  
  120.    return ( bSearch )
  121.  
  122.    function refreshRowState      
  123.       // Refresh the RowState control if found.
  124.       local thisForm, bFound
  125.  
  126.       thisForm = form
  127.       bFound   = false
  128.                     
  129.       for i = 1 to thisForm.elements.size
  130.           if ( UPPER( thisForm.elements[i].className ) == "ROWSTATE" )
  131.              thisForm.elements[i].refreshText()
  132.              bFound := true
  133.           endif
  134.       next
  135.    return ( bFound )
  136. endclass
  137.  
  138.  
  139. class BitmapAppend( ParentObj ) of BitmapData( ParentObj ) custom 
  140.    with ( this )
  141.       upBitmap := "RESOURCE:2 PS_APPEND"
  142.       speedTip := "Add Row"
  143.       onClick  := { ; this.form.rowset.beginAppend() ;
  144.                     ; super::RefreshRowState() }
  145.    endwith
  146. endclass
  147.  
  148. class BitmapDelete( ParentObj ) of BitmapData( ParentObj ) custom 
  149.    with ( this )
  150.       upBitmap := "RESOURCE:2 PS_DELETE"
  151.       speedTip := "Delete Row"
  152.       onClick  := class::BitmapDelete_onClick
  153.    endwith
  154.  
  155.    function BitmapDelete_onClick
  156.       local bDelete
  157.       bDelete = false
  158.  
  159.       if ( not this.form.rowset.endOfSet )
  160.  
  161.          if ( MSGBOX("You are about to delete the current row." ;
  162.               + CHR(13) ;
  163.               + "Click Yes to delete the current row.", ;
  164.               "Alert", ;
  165.               4 ) == 6 )
  166.  
  167.             bDelete := this.form.rowset.delete()
  168.  
  169.             if ( this.form.rowset.endOfSet )
  170.               this.form.rowset.last()
  171.             endif
  172.  
  173.          endif
  174.  
  175.       endif
  176.  
  177.       super::refreshRowState()
  178.    return ( bDelete )
  179.  
  180. endclass
  181.  
  182. class BitmapSave( ParentObj ) of BitmapData( ParentObj ) custom 
  183.    with ( this )
  184.       upBitmap := "RESOURCE:2 PS_SAVE"
  185.       speedTip := "Save Row"
  186.       onClick  := { ; this.form.rowset.save() ;
  187.                     ; super::refreshRowState() }
  188.    endwith
  189. endclass
  190.                                
  191. class BitmapAbandon( ParentObj ) of BitmapData( ParentObj ) custom 
  192.    with ( this )
  193.       upBitmap := "RESOURCE:2 PS_ABANDON"
  194.       speedTip := "Abandon"
  195.       onClick  := { ; this.form.rowset.abandon() ;
  196.                     ; super::refreshRowState() }
  197.    endwith
  198. endclass
  199.  
  200. class BitmapLocate(ParentObj) of BitmapData( ParentObj ) custom
  201.    with ( this )
  202.       upBitmap := "RESOURCE:2 PS_LOCATE"
  203.       speedTip := "Find Row"
  204.       onClick  := class::bitmapLocate_onClick
  205.    endwith
  206.  
  207.    function bitmapLocate_onClick
  208.       // Change image and toggle other controls
  209.       // when entering and exiting search mode.
  210.  
  211.       if ( this.form.rowset.state == 5 ) 
  212.          this.upBitmap = "RESOURCE:2 PS_LOCATE"
  213.          this.speedTip = "Find Row"
  214.          this.form.rowset.applyLocate()
  215.       else
  216.          this.upBitmap = "RESOURCE:2 PS_RUN"
  217.          this.speedTip = "Start Search" 
  218.          this.form.rowset.beginLocate()
  219.       endif
  220.       super::toggleSearch(this)
  221.    return ( this.form.rowset.state )
  222. endclass
  223.  
  224. class BitmapFilter( ParentObj ) of BitmapData( ParentObj ) custom 
  225.    with ( this )
  226.       upBitmap := "RESOURCE:2 PS_FILTER"
  227.       speedTip := "Filter Rowset"
  228.       onClick  := class::bFilter_onClick
  229.    endwith
  230.  
  231.    function bFilter_onClick
  232.       // Change image and toggle other controls
  233.       // when entering and exiting search mode.
  234.  
  235.       if ( this.form.rowset.state == 4 ) 
  236.          this.upBitmap = "RESOURCE:2 PS_FILTER"
  237.          this.speedTip = "Filter Rowset"
  238.          this.form.rowset.applyFilter()     
  239.       else
  240.          this.upBitmap = "RESOURCE:2 PS_RUN"
  241.          this.speedTip = "Apply Filter"
  242.          this.form.rowset.beginFilter()
  243.       endif
  244.       super::toggleSearch(this)
  245.    return ( this.form.rowset.state )
  246. endclass
  247.  
  248. class BitmapEdit(ParentObj) of BitmapData( ParentObj ) custom 
  249.    with ( this )
  250.       upBitmap := "RESOURCE:2 PS_EDIT"
  251.       speedTip := "Edit Row"
  252.       onClick  := { ; this.form.rowset.beginEdit() ;
  253.                     ; super::RefreshRowState() }
  254.    endwith
  255. endclass
  256.  
  257.  
  258. class BitmapFirst( ParentObj ) of BitmapData( ParentObj ) custom 
  259.    with ( this )
  260.       upBitmap := "RESOURCE:2 PS_FIRST"
  261.       speedTip := "First Row"
  262.       onClick  := { ; this.form.rowset.first() ;
  263.                     ; super::RefreshRowState() }
  264.    endwith
  265. endclass
  266.  
  267. class BitmapPrevious( ParentObj ) of BitmapData( ParentObj ) custom 
  268.    with ( this )
  269.       upBitmap := "RESOURCE:2 PS_PREV"
  270.       speedTip := "Previous Row"
  271.       onClick  := { ; if ( NOT this.form.rowset.next(-1)) ;
  272.                     ;    this.form.rowset.next() ; 
  273.                     ; endif ;
  274.                     ; super::RefreshRowState() }
  275.    endwith
  276. endclass
  277.  
  278. class BitmapNext( ParentObj ) of BitmapData( ParentObj ) custom 
  279.    with ( this )
  280.       upBitmap := "RESOURCE:2 PS_NEXT"
  281.       speedTip := "Next Row"
  282.       onClick  := { ; if ( NOT this.form.rowset.next() ) ;
  283.                     ;    this.form.rowset.next(-1) ;
  284.                     ; endif ;
  285.                     ; super::RefreshRowState() }
  286.    endwith
  287. endclass
  288.  
  289. class BitmapLast(ParentObj) of BitmapData( ParentObj ) custom 
  290.    with ( this )
  291.       upBitmap := "RESOURCE:2 PS_LAST"
  292.       speedTip := "Last Row"
  293.       onClick  := { ; this.form.rowset.last() ;
  294.                     ; super::RefreshRowState() }
  295.    endwith
  296. endclass
  297.  
  298. class BarDataEdit( ParentObj, Name ) of Container( ParentObj, Name ) custom
  299.    SET TALK OFF
  300.    with ( this )
  301.       width  := 192
  302.       height := 32
  303.       metric := 6 // pixels
  304.       borderStyle := 3 // none
  305.    endwith
  306.  
  307.    this.bitmapAppend = new BitmapAppend( this )
  308.                             
  309.    this.bitmapDelete = new BitmapDelete( this )
  310.    with ( this.bitmapDelete )
  311.       left     := 32
  312.       width    := 32
  313.       height   := 32
  314.       fontSize := 8
  315.       metric   := 6 // pixels
  316.    endwith
  317.  
  318.    this.bitmapSave = new BitmapSave( this )
  319.    with ( this.bitmapSave )
  320.       left     := 64
  321.       width    := 32
  322.       height   := 32
  323.       fontSize := 8
  324.       metric   := 6 // pixels
  325.    endwith
  326.         
  327.    this.bitmapAbandon = new BitmapAbandon( this )
  328.    with ( this.bitmapAbandon )
  329.       left     := 96
  330.       width    := 32
  331.       height   := 32
  332.       fontSize := 8
  333.       metric   := 6 // pixels
  334.    endwith
  335.  
  336.    this.bitmapFilter = new BitmapFilter( this )
  337.    with ( this.bitmapFilter )
  338.       left     := 128
  339.       width    := 32
  340.       height   := 32
  341.       fontSize := 8
  342.       metric   := 6 // pixels
  343.    endwith
  344.         
  345.    this.bitmapLocate = new BitmapLocate( this )
  346.    with ( this.bitmapLocate )
  347.       left     := 160
  348.       width    := 32
  349.       height   := 32
  350.       fontSize := 8
  351.       metric   := 6 // pixels
  352.    endwith
  353.  
  354.    function barToggle( bSearch, current )
  355.       with ( this )
  356.          bitmapAppend.enabled  := ( not bSearch )
  357.          bitmapDelete.enabled  := ( not bSearch )
  358.          bitmapSave.enabled    := ( not bSearch )
  359.          bitmapAbandon.enabled := ( not bSearch )
  360.       endwith
  361.       if ( current <> this.bitmapFilter )
  362.          this.BitmapFilter.enabled := ( not bSearch )
  363.       endif
  364.       if ( current <> this.bitmapLocate )
  365.          this.BitmapLocate.enabled := ( not bSearch )
  366.       endif
  367.    return ( bSearch )
  368.  
  369. endclass
  370.  
  371.  
  372. class BarDataVCR( ParentObj, Name ) of Container( ParentObj, Name ) custom
  373.    SET TALK OFF
  374.    with ( this )
  375.       width  := 128
  376.       height := 32
  377.       metric := 6 // pixels
  378.       borderStyle := 3 // none
  379.    endwith
  380.  
  381.    this.bitmapFirst = new BitmapFirst( this )
  382.  
  383.    this.bitmapPrevious = new BitmapPrevious( this )
  384.    with ( this.bitmapPrevious )
  385.       left     := 32
  386.       width    := 32
  387.       height   := 32
  388.       fontSize := 8
  389.       metric   := 6 // pixels
  390.    endwith
  391.  
  392.    this.bitmapNext = new BitmapNext( this )
  393.    with ( this.bitmapNext )
  394.       left     := 64
  395.       width    := 32
  396.       height   := 32
  397.       fontSize := 8
  398.       metric   := 6 // pixels
  399.    endwith
  400.         
  401.    this.bitmapLast = new BitmapLast( this )
  402.    with ( this.bitmapLast )
  403.       left     := 96
  404.       width    := 32
  405.       height   := 32
  406.       fontSize := 8
  407.       metric   := 6 // pixels
  408.    endwith
  409.  
  410.    function barToggle( bSearch, current )
  411.       with ( this )
  412.          bitmapFirst.enabled    := ( not bSearch )
  413.          bitmapPrevious.enabled := ( not bSearch )
  414.          bitmapNext.enabled     := ( not bSearch )
  415.          bitmapLast.enabled     := ( not bSearch )
  416.       endwith
  417.    return ( bSearch )
  418.  
  419. endclass
  420.  
  421.  
  422.  
  423. // State
  424.  
  425. class RowState( ParentObj ) of Text( ParentObj ) custom
  426.    SET TALK OFF
  427.    with ( this )
  428.       onOpen     := class::RefreshText
  429.       height     := 1
  430.       width      := 18
  431.       metric     := 0
  432.       text       := "Unknown State"
  433.       fontSize   := 8
  434.       fontBold   := false
  435.       fontItalic := true
  436.    endwith
  437.      
  438.    function refreshText
  439.       // Refresh text property
  440.       local   nState
  441.       private rType
  442.       rType = this.form.rowset
  443.       if ( TYPE( "rType" ) == "U" )
  444.          this.text = "Rowset Not Found"
  445.       else
  446.          nState = this.form.rowset.state
  447.          do case 
  448.             case ( nState == 0 )
  449.                  this.text := "Closed" 
  450.             case ( nState == 1 )
  451.                  this.text := "Read Only"
  452.             case ( nState == 2 )
  453.                  this.text := "Update"
  454.             case ( nState == 3 )
  455.                  this.text := "Append"
  456.             case ( nState == 4 )
  457.                  this.text := "Filter"
  458.             case ( nState == 5 )
  459.                  this.text := "Locate"
  460.             otherwise
  461.                  this.text := "Unknown State"
  462.          endcase
  463.       endif
  464.    return ( this.text )
  465. endclass
  466.  
  467. // Push Buttons
  468.  
  469. class ButtonData( ParentObj ) of PushButton( ParentObj ) custom 
  470.    SET TALK OFF
  471.    with ( this )
  472.       onOpen   := class::buttonData_onOpen
  473.       fontSize := 8
  474.       fontBold := false 
  475.       width    := 10
  476.       height   := 1.2
  477.       metric   := 0
  478.    endwith
  479.  
  480.    function buttonData_onOpen
  481.       private rType
  482.       rType = this.form.rowset
  483.       this.visible = ( TYPE( "rType" ) <> "U" )
  484.    return ( this.visible )
  485.  
  486.    function toggleSearch( current )  
  487.       local bSearch, sControlList
  488.       bSearch = ( this.form.rowset.state == 4 ) OR ;
  489.                 ( this.form.rowset.state == 5 )
  490.       sControlList = DATACONTROLS1 + DATACONTROLS2 + ;
  491.                      DATACONTROLS3 + DATACONTROLS4
  492.  
  493.       for i = 1 to this.parent.elements.size
  494.           if ( this.parent.elements[i].className $ sControlList )
  495.              if ( this.parent.elements[i] <> current ) 
  496.                 this.parent.elements[i].visible = ( not bSearch ) 
  497.              endif
  498.           endif
  499.       next
  500.                     
  501.    return ( bSearch )
  502.  
  503.    function refreshRowState
  504.       // Refresh the RowState if found.
  505.       local vProp, bRefresh
  506.       bREfresh = false
  507.  
  508.       for i = 1 to this.parent.elements.size
  509.           if ( UPPER( this.parent.elements[i].className ) == "ROWSTATE" )
  510.              this.parent.elements[i].refreshText()
  511.              bRefresh := true
  512.           endif
  513.       next
  514.  
  515.    return ( bRefresh )
  516.  
  517. endclass
  518.  
  519. class ButtonAppend( ParentObj ) of ButtonData( ParentObj ) custom
  520.    with ( this )
  521.       text    := "Add"
  522.       onClick := { ; this.form.rowset.beginAppend() ;
  523.                    ; super::RefreshRowState() }
  524.    endwith
  525. endclass
  526.  
  527. class ButtonDelete(ParentObj ) of ButtonData( ParentObj ) custom 
  528.    with ( this )
  529.       text    := "Delete"
  530.       onClick := class::buttonDelete_onClick
  531.    endwith
  532.  
  533.    function buttonDelete_onClick
  534.       local bDelete
  535.       bDelete = false
  536.  
  537.       if ( not this.form.rowset.endOfSet )
  538.  
  539.          if ( MSGBOX("You are about to delete the current row." ;
  540.               + CHR(13) ;
  541.               + "Click Yes to delete the current row.", ;
  542.               "Alert", ;
  543.               4 ) == 6 )
  544.  
  545.             bDelete := this.form.rowset.delete()
  546.  
  547.             if (this.form.rowset.endOfSet)
  548.                this.form.rowset.last()
  549.             endif
  550.  
  551.          endif
  552.  
  553.       endif
  554.  
  555.       super::refreshRowState()
  556.    return ( bDelete )
  557.  
  558. endclass
  559.  
  560. class ButtonSave( ParentObj ) of ButtonData( ParentObj ) custom
  561.    with ( this )
  562.        text    := "Save"
  563.        onClick := { ; this.form.rowset.save() ;
  564.                     ; super::RefreshRowState() }
  565.    endwith
  566. endclass
  567.  
  568. class ButtonAbandon( ParentObj ) of ButtonData( ParentObj ) custom
  569.    with ( this )
  570.       text    := "Abandon"
  571.       onClick := { ; this.form.rowset.abandon() ;
  572.                    ; super::RefreshRowState() }
  573.    endwith
  574. endclass
  575.  
  576. class ButtonLocate( ParentObj ) of ButtonData( ParentObj ) custom
  577.    with ( this )
  578.       text    := "Locate"
  579.       onClick := class::buttonLocate_onClick
  580.    endwith
  581.  
  582.    function buttonLocate_onClick
  583.       // Change text and toggle other controls
  584.       // when entering and exiting search mode.
  585.  
  586.       if ( this.form.rowset.state == 5 ) 
  587.          this.text = "Locate"
  588.          this.form.rowset.applyLocate()
  589.       else 
  590.          this.text = "Start Search"
  591.          this.form.rowset.beginLocate()
  592.       endif
  593.       super::toggleSearch(this)
  594.    return ( this.form.rowset.state )
  595. endclass
  596.  
  597. class ButtonFilter( ParentObj ) of ButtonData( ParentObj ) custom
  598.    with ( this )
  599.       text    := "Filter"
  600.       onClick := class::buttonFilter_onClick
  601.    endwith
  602.  
  603.    function buttonFilter_onClick 
  604.       // Change text and toggle other controls
  605.       // when entering and exiting search mode.
  606.  
  607.       if ( this.form.rowset.state == 4 ) 
  608.          this.text = "Filter"
  609.          this.form.rowset.applyFilter()      
  610.       else 
  611.          this.text = "Start Search"
  612.          this.form.rowset.beginFilter()
  613.       endif
  614.       super::toggleSearch(this)
  615.    return ( this.form.rowset.state )
  616. endclass
  617.  
  618.  
  619. class ButtonEdit( ParentObj ) of ButtonData( ParentObj ) custom
  620.    with ( this )
  621.       text    := "Edit"
  622.       onClick := { ; this.form.rowset.beginEdit() ;
  623.                    ; super::RefreshRowState() }
  624.    endwith
  625. endclass
  626.  
  627. class ButtonFirst( ParentObj ) of ButtonData( ParentObj ) custom
  628.    with ( this )
  629.       text    := "First"
  630.       onClick := { ; this.form.rowset.first() ;
  631.                    ; super::RefreshRowState() }
  632.    endwith
  633. endclass
  634.  
  635. class ButtonPrevious( ParentObj ) of ButtonData( ParentObj ) custom
  636.    with ( this )
  637.       text    := "Previous"
  638.       onClick := { ; if ( NOT this.form.rowset.next(-1) ) ;
  639.                    ;    this.form.rowset.next() ; 
  640.                    ; endif ;
  641.                    ; super::RefreshRowState() }
  642.    endwith
  643. endclass
  644.  
  645. class ButtonNext( ParentObj ) of ButtonData( ParentObj ) custom
  646.    with ( this )
  647.       text    := "Next"
  648.       onClick := { ; if ( NOT this.form.rowset.next() ) ;
  649.                    ;    this.form.rowset.next(-1) ; 
  650.                    ; endif ;
  651.                    ; super::RefreshRowState() }
  652.    endwith
  653. endclass
  654.  
  655. class ButtonLast( ParentObj ) of ButtonData( ParentObj ) custom
  656.    with ( this )
  657.       text    := "Last"
  658.       onClick := { ; this.form.rowset.last() ;
  659.                    ; super::RefreshRowState() }
  660.    endwith
  661. endclass
  662.  
  663.  
  664.